namespace ContractorTimesheet.DataModel
{
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;

    public partial class TimesheetDBModel : DbContext
    {
        public TimesheetDBModel() : base("name=TimesheetDB") { }

        public virtual DbSet<Holiday> Holidays { get; set; }

        public virtual DbSet<User> Users { get; set; }

        public virtual DbSet<Leave> Leaves { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Holiday>()
                .Property(e => e.Year)
                .IsFixedLength();

            modelBuilder.Entity<Holiday>()
                .Property(e => e.Month)
                .IsFixedLength();

            modelBuilder.Entity<Holiday>()
                .Property(e => e.Day)
                .IsFixedLength();

            modelBuilder.Entity<Leave>()
                .Property(e => e.Year)
                .IsFixedLength();

            modelBuilder.Entity<Leave>()
                .Property(e => e.Month)
                .IsFixedLength();

            modelBuilder.Entity<Leave>()
                .Property(e => e.Day)
                .IsFixedLength();

            modelBuilder.Entity<User>()
                .Property(e => e.Password)
                .IsUnicode(false);

            modelBuilder.Entity<User>()
                .Property(e => e.PasswordSalt)
                .IsUnicode(false);

            modelBuilder.Entity<User>()
                .HasMany(e => e.Leaves)
                .WithRequired(e => e.User)
                .WillCascadeOnDelete(true);

        }
    }
}
